package com.baidu.dao;

import com.baidu.pojo.Order;
import com.baidu.pojo.Orders;
import com.baidu.pojo.Ticket;
import com.baidu.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface OrdersMapper {
    //    买票 用户金额- 票- 添加订单+
    @Insert("INSERT INTO orders(uid,tid,otime,oquantity,ostate) VALUES(#{uid},#{tid},#{otime},#{oquantity},0)")
    public void addOrder(Order order);
    //    金额-
    @Update("UPDATE users SET ucount=#{ucount} WHERE uid=#{uid}")
    public void updateUcount(User user);
    @Update("UPDATE ticket SET tnum=#{tnum} WHERE tid=#{tid}")
    public void updateTNum(Ticket ticket);
    //新增订单
    @Insert("INSERT INTO orders (uid,tid,otime,oquantity,ostate) VALUES(#{uid},#{tid},#{otime},#{oquantity},1);")
    public void addOrders(Orders orders);

    //根据订单号查询订单信息
    @Select("SELECT * FROM orders WHERE oid=#{oid} and ostate!=1")
    public Orders getOrdersByOid(Integer oid);

    //根据订单号修改订单信息
    @Update("UPDATE orders SET tid=#{tid},otime=#{otime},oquantity=#{oquantity} WHERE oid=#{oid}")
    public void updateOrdersByOid(Orders orders);

    //根据订单号删除订单信息
    @Update("UPDATE orders SET ostate=1 WHERE oid=#{oid}")
    public void deleteOrdersById(Integer oid);

    //分页查询总记录数
    @Select("select COUNT(*) from orders where ostate!=1")
    public int count();

    //    查询所有订单信息
    public List<Orders> getAllOrders();

    //分页查询所有用户信息,以及关联的角色信息 第一个参数表示起始位置，第二个参数表示页面容量
    public List<Orders> getByPage(@Param("start")Integer start, @Param("pageSize")Integer pageSize);

    //    根据指定tid查询订单信息
    public Orders getOrderByTid(Integer tid);

//    获取全部订单 分页
    public List<Order> getAllOrderByUId(Integer uid);
    @Select("select COUNT(*) from orders where ostate!=1 and uid = #{uid}")
    public Integer getAllOrderByUIdCount(Integer uid);
    public List<Order> getAllOrderByUIdByPage(@Param("start")Integer start, @Param("pageSize")Integer pageSize,@Param("uid")Integer uid);
//    updateOrderState
    @Update("UPDATE orders SET ostate=#{ostate} WHERE oid=#{oid}")
    public void updateOrderState(Order order);
}
